package gui;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;


public class torsten {
    String userName;
    String userPword;
	// static String userName;
	// static String userPword;
	
	
	public static void main(String[] args) {
		SwingUtilities.invokeLater(()->{torsten tt = new torsten();
			JFrame f = new JFrame();
			f.setVisible(true);
			f.setSize(400,400);
			// f.setExtendedState(JFrame.MAXIMIZED_BOTH);
			f.setLocationRelativeTo(null);
			f.setTitle("用户登录界面");
			
			Container con = f.getContentPane();
			con.setLayout(new GridLayout(5,1));
			
			JPanel pan1 = new JPanel();
			Icon pic = new ImageIcon("C:/Users/tqy8264/Desktop/tt.png");
			JLabel J_pic = new JLabel(pic);
			pan1.add(J_pic);
			con.add(pan1);
			
			JPanel pan2 = new JPanel();
			JLabel title = new JLabel("欢迎登录");
			title.setFont(new Font("宋体", Font.BOLD,20));
			pan2.add(title);
			con.add(pan2);
			
			JPanel pan3 = new JPanel();
			JLabel name = new JLabel("用户名：");
			TextField tf_name = new TextField(20);
			tf_name.setText("请在此处输入用户名");
			pan3.add(name);pan3.add(tf_name);
			con.add(pan3);
			
			JPanel pan4 = new JPanel();
			JLabel pass = new JLabel("密     码：");
			TextField tf_pass = new TextField(20);
			tf_pass.setText("请在此处输入密码");
			pan4.add(pass);pan4.add(tf_pass);
			con.add(pan4);
			
			JPanel pan5 = new JPanel();
			JButton b_log = new JButton("登录");
			// b_log.addActionListener(new ActionListener(){
	
			// 	@Override
			// 	public void actionPerformed(ActionEvent arg0) {
			//         torsten.userName = tf_name.getText();
			//         torsten.userPword = tf_pass.getText();
					
			// 		if(userName.equals("torsten")){
			//             JOptionPane.showMessageDialog(null, "登录成功");
			//         }else{
			//             JOptionPane.showMessageDialog(null, "登录失败");
			//         }
					
			// 	}
				
			// });
			b_log.addActionListener(new ActionListener(){
	
				@Override
				public void actionPerformed(ActionEvent arg0) {
					tt.userName = tf_name.getText();
					// torsten.userName = tf_name.getText();
					// torsten.userPword = tf_pass.getText();
					tt.userPword = tf_pass.getText();
					
					// userName.equals("torsten")&&userPword.equals("123456")
					if(tt.userName.equals("李四")&&tt.userPword.equals("123456")){
						JOptionPane.showMessageDialog(null, "登录成功");
						SwingUtilities.invokeLater(new Runnable() {
							public void run() {
								new index();
							}
						});
						f.dispose();
					}else{
						JOptionPane.showMessageDialog(null, "登录失败");
					}
					
				}
				
			});
			JButton b_exit = new JButton("退出");
			b_exit.addActionListener(new ActionListener(){
	
				@Override
				public void actionPerformed(ActionEvent arg0) {
					System.exit(0);
					
				}
				
			});
			pan5.add(b_log);pan5.add(b_exit);
			con.add(pan5);
			});
		
		
	}
}
